package cn.hua.trip.base.domain;

import cn.hua.trip.base.util.DateUtil;
import cn.hua.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class TravelCommend extends BaseDomain{

    public static final int TYPE_WEEK = 1; //周推荐
    public static final int TYPE_MONTH = 2;//月推荐
    public static final int TYPE_STRATEGY = 3;//攻略推荐

    private Travel travel; //关联的游记对象

    private String title;//推荐标题

    private String subTitle;//推荐副标题

    private String coverUrl;//封面

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date schedule;//推荐时间

    private Integer type;//推荐类型

    public String getJsonString(){
        Map<String,Object> map = new HashMap<>();
        map.put("title",title);
        map.put("id",getId());
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        map.put("schedule", DateUtil.formatDate(schedule));
        map.put("type",type);
        if (travel !=null){
            map.put("travelId",travel.getId());
        }
        return JSONUtil.toJSONString(map);
    }


    public String getTypename(){
        String temp = "";
        if (type==TYPE_WEEK) {
            temp="";
        }else if(type==TYPE_MONTH){
            temp="月推荐";
        }else if (type==TYPE_STRATEGY){
            temp="攻略推荐";
        }
        return temp;
    }
}